package com.movitech.mobile.cz.base.purchase.controller;


import com.movitech.mobile.cz.base.purchase.bizvo.MyFormRequestVO;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.movitech.mobile.cz.base.modules.controller.RestReturnResult;
import com.movitech.mobile.cz.base.purchase.entity.WFlowForm;
import com.movitech.mobile.cz.base.purchase.service.WFlowFormService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 * WFlowForm 前端控制器
 * </p>
 *
 * @author Movitech Mobile
 * @since 2018-03-15
 */
@RestController
@RequestMapping("/v1/wFlowForm")
@Api(value = "采购列表基础操作接口", description = "采购列表基础操作接口")
public class WFlowFormController {
    @Autowired
    private WFlowFormService wFlowFormService;

    @GetMapping("/allList")
    @ApiOperation(
            value = "获取所有的采购列表接口",
            notes = "获取所有的采购列表接口",
            response = WFlowForm.class
    )
    public RestReturnResult list() {
        RestReturnResult restReturnResult = RestReturnResult.success();
        Page<WFlowForm> page = wFlowFormService.selectPage(new Page<WFlowForm>());
        restReturnResult.setData(page);
        return restReturnResult;
    }

    @PostMapping("/searchList/{pageNumber}")
    @ApiOperation(
            value = "采购列查询接口",
            notes = "采购列查询接口",
            response = WFlowForm.class
    )
    public RestReturnResult searchList(@RequestBody WFlowForm wFlowForm,
                @ApiParam(value = "分页页数")@PathVariable Integer pageNumber) {
        RestReturnResult restReturnResult = RestReturnResult.success();
        Page<WFlowForm> page = new Page<>();
        page.setCurrent(pageNumber);
        EntityWrapper wrapper = new EntityWrapper<>();
        wrapper.setEntity(wFlowForm);
        page = wFlowFormService.selectPage(page,wrapper);
        restReturnResult.setData(page);
        return restReturnResult;
    }

    @GetMapping("/getWFlowForm/{id}")
    @ApiOperation(
            value = "采购列表根据ID获取接口",
            notes = "采购列表根据ID获取接口",
            response = WFlowForm.class
    )
    public RestReturnResult addWFlowForm(@PathVariable String id) {
        RestReturnResult restReturnResult = RestReturnResult.success();
        WFlowForm wFlowForm = wFlowFormService.selectById(id);
        restReturnResult.setData(wFlowForm);
        return restReturnResult;
    }

    @PostMapping("/add")
    @ApiOperation(
            value = "采购列表添加接口",
            notes = "采购列表添加接口",
            response = WFlowForm.class
    )
    public RestReturnResult add(@RequestBody WFlowForm wFlowForm) {
        RestReturnResult restReturnResult = RestReturnResult.success();
        wFlowFormService.insert(wFlowForm);
        restReturnResult.setData(wFlowForm);
        return restReturnResult;
    }

    @PutMapping("/update")
    @ApiOperation(
            value = "采购列表更新接口",
            notes = "采购列表更新接口",
            response = WFlowForm.class
    )
    public RestReturnResult update(@RequestBody WFlowForm wFlowForm) {
        RestReturnResult restReturnResult = RestReturnResult.success();
        wFlowFormService.updateById(wFlowForm);
        restReturnResult.setData(wFlowForm);
        return restReturnResult;
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(
            value = "采购列表通过ID删除接口",
            notes = "采购列表通过ID删除接口",
            response = WFlowForm.class
    )
    public RestReturnResult update(@PathVariable String id) {
        RestReturnResult restReturnResult = RestReturnResult.success();
        wFlowFormService.deleteById(id);
        return restReturnResult;
    }

    @PostMapping("/getMyFormList")
    @ApiOperation(
            value = "外网招标管理列表接口",
            notes = "外网招标管理列表接口",
            response = WFlowForm.class
    )
    public RestReturnResult getMyFormList(HttpServletRequest request, HttpServletResponse response, @RequestBody MyFormRequestVO myFormRequestVO) {
        RestReturnResult restReturnResult = RestReturnResult.success();
        try {
            restReturnResult = wFlowFormService.getMyFormList(request,response,myFormRequestVO);
        }catch (Exception e){
            e.printStackTrace();
            restReturnResult = RestReturnResult.error();
        }
        return restReturnResult;
    }

    @PostMapping("/getBidNodeDetail/{formId}")
    @ApiOperation(
            value = "外网招标管理投标节点详情",
            notes = "外网招标管理投标节点详情",
            response = WFlowForm.class
    )
    public RestReturnResult getBidNodeDetail(@PathVariable String formId) {
            return wFlowFormService.getBidNodeDetail(formId);
    }

}

